﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class update_teacher : System.Web.UI.Page
{
    string Tno;
    string Tname;
    string course1;
    string course2;
    string course3;
    string course4;
    string dept;

    protected void Page_Load(object sender, EventArgs e)
    {
        Tno = Request.QueryString["Tno"];
        Tname = Request.QueryString["Tname"];
        course1 = Request.QueryString["course1"];
        course2 = Request.QueryString["course2"];
        course3 = Request.QueryString["course3"];
        course4 = Request.QueryString["course4"];
        dept = Request.QueryString["dept"];

        Label1.Text = Tno;
        Label2.Text = Tname;
        Label3.Text = course1;
        Label4.Text = course2;
        Label5.Text = course3;
        Label6.Text = dept;
        Label7.Text = course4;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);

        try
        {
            if (string.IsNullOrEmpty(TextBox1.Text.ToString()) || string.IsNullOrEmpty(TextBox2.Text.ToString()) || string.IsNullOrEmpty(TextBox3.Text.ToString()) || string.IsNullOrEmpty(DropDownList1.Text.ToString()) )
            {
                Response.Write("<h1>更新失败，教师的教师号、教师名、课程1、学院不能为空！！</h1>");
            }
            else
            {

                connection.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = connection;

                string str_sql = " update Teacher set Tno='" + TextBox1.Text.ToString() + "' , Tname='" + TextBox2.Text.ToString() + "' , course1='" + TextBox3.Text.ToString() + "' , course2='" + TextBox4.Text.ToString() + "' , course3= '" + TextBox5.Text.ToString() + "' , course4= '" + TextBox6.Text.ToString() + "'  , dept='" + DropDownList1.Text.ToString() + "'  ";
                comm.CommandText = str_sql;
                //comm.ExecuteScalar();  //如果为查询语句，则用ExecuteScalar()；否则，用ExecuteNonQuery()
                comm.ExecuteNonQuery();

                Response.Write("<h1>成功更新教师信息！</h1>");
            }
        }

        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        connection.Close();//关闭数据库连接
    }
}